﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Utility class for data
/// Author: Jeff
/// Date: 04/08/2008
/// </summary>
public class DataUtil
{
	public DataUtil()
	{
		//
		// TODO:No use now
		//
	}

    /// <summary>
    /// Convert object array to int array
    /// </summary>
    /// <param name="objs">array of objects</param>
    /// <returns>array of ints</returns>
    public static int[] ObjsToInts(Object[] objs)
    {
        int[] a = new int[objs.Length];
        for (int i = 0; i < objs.Length; i++)
        {
            a[i] = (int)objs[i];
        }
        return a;
    }

    /// <summary>
    /// Convert the ints string to int array. EX: ints string is in the format => "1,3,4,5"
    /// </summary>
    /// <param name="ints">ints string is in the format => "1,3,4,5"</param>
    /// <returns>array of ints</returns>
    public static int[] StringIntsToInts(String ints)
    {
        String[] ss = ints.Split(',');
        int[] a = new int[ss.Length];
        for (int i = 0; i < ss.Length; i++)
        {
            a[i] = Convert.ToInt32(ss[i]);
        }
        return a;
    }
	
    /// <summary>
    /// Convert the ints string to int array. EX: ints string is in the format => "1,3,4,5"
    /// </summary>
    /// <param name="ints">ints string is in the format => "1,3,4,5</param>
    /// <param name="sep">seperator</param>
    /// <returns>array of ints</returns>
	public static int[] StringIntstoInts(String ints, char sep)
	{
		String[] ss = ints.Split(sep);
        int[] a = new int[ss.Length];
        for (int i = 0; i < ss.Length; i++)
        {
            a[i] = Convert.ToInt32(ss[i]);
        }
        return a;
	}

    public static int StringToInt(String _int)
    {
        return Convert.ToInt32(_int);
    }

    public static int OjectToInt(Object obj)
    {
        return Convert.ToInt32(obj);
    }

    public static String ObjetToString(Object obj)
    {
        if (obj == null)
            return null;
        else
            return obj.ToString();
    }

    /// <summary>
    /// Return true, whether the string is empty(null, "", or...)
    /// </summary>
    /// <param name="s">input string</param>
    /// <returns></returns>
    public static bool IsEmptyString(String s)
    {
        if (s == null)
            return true;
        else if (String.Empty == s)
            return true;
        else if (s.Length == 0)
            return true;
        return false;
    }

    
}
